package com.jf3q.sup.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jf3q.sup.domain.Menus;
import com.jf3q.sup.domain.Users;
import com.jf3q.sup.mapper.MenusMapper;
import com.jf3q.sup.service.MenusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 */
@Service
public class MenusServiceImpl extends ServiceImpl<MenusMapper, Menus>
    implements MenusService{

    @Autowired
    MenusMapper menusMapper;

    @Autowired
    UsersServiceImpl usersService;


    @Override
    public List<Menus> getMenu() {
        String username = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
        Users users = (Users)usersService.loadUserByUsername(username);
        List<Menus> menus = menusMapper.getMenu(users.getId(), 0);
        for (Menus menu : menus) {
            menu.setChildren(menusMapper.getMenu(users.getId(), menu.getId()));
        }
        return menus;
//        return find(0,username);
    }

//    private List<Menus> find(Integer parentId, String username) {
//        List<Menus> menusList = menusMapper.getMenu(parentId,username);
//        for (Menus menus : menusList) {
//            menus.setChildren(menusMapper.getMenu(menus.getId(),username));
//        }
//        return menusList;
//    }
}




